/**
 * 
 */
package kernel_gui.gui.extended;


import java.awt.Component;


/**
 * @author Yoyo
 *
 */
public class ELoginFrame extends kernel_gui.gui.generic.graphic.LoginFrame {
	

	/**
	 * 
	 */
	private static final long serialVersionUID = 1162169405957147072L;

	public ELoginFrame() {
				
		setExecuteOnCancel(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				Component components[] = MainPanel.getComponents();
				for (Component c : components) {
					c.setEnabled(true);
				}
			}
		});
		
		setExecuteBeforeLongRequest(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				Component components[] = MainPanel.getComponents();
				for (Component c : components) {
					c.setEnabled(false);
				}
				
			}
		});
	}
                                             

    protected void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {
		
    	int requestID = executeBeforeLongRequest(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				boolean ans = (Boolean) answer;
				if(ans){
					ELoginFrame.this.openAnotherFrame(EMainMenuFrame.class, true);
				}
				
			}
		});
    	
		String userName = userNameTextField.getText();
		String password = String.valueOf(passwordTextField.getPassword());
		boolean loginAsAdmin = loginAsAdminCheckBox.isSelected(); 
		kernel.authenticateUser(userName, password, loginAsAdmin,requestID);
    }                                                                                  
    
    protected void createUserButtonActionPerformed(java.awt.event.ActionEvent evt) {
        openAnotherFrame(ENewUserLoginFrame.class, true);
    }


	protected void calledAsLongRequestFromOtherFrame(int requestID) {
		/*Will never be called from another window as long request*/
	}


	@Override
	protected void setWindowComponentsWhenCalledFromAnotherFrame() {
		/*not needed*/
		
	}

}
